class Solution {
public:
    ListNode* deleteNode(ListNode* head, int val) {
        if (head->val == val)return head->next;
        ListNode* pre = head, * cur = head->next;
        while (cur) {
            if (cur->val == val)break;
            pre = cur;
            cur = cur->next;
        }
        if (cur)pre->next = cur->next;
        return head;
    }
};